package com.king.login.controller;

import com.king.login.entity.Member;
import com.king.login.service.MemberService;
import com.king.platform.enmu.ResultEnum;
import com.king.platform.entity.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>todo 用户登录控制器</p>
 * @author: cuizx
 * @created: 2024/3/29 21:02
 * @version v1.0.1
 * @copyright: Copyright (c)  cuizx
 */
@Api(tags = "login-api")
@RestController
@RequestMapping("/login")
public class LoginController
{

  @Autowired
  private MemberService memberService;

  /**
   * <p>todo 用户登录</p>
   * @param: userName
   * @param: password
   * @return: com.king.platform.entity.BaseResult<com.king.login.entity.Member>
   * @author: cuizx
   * @date: 2024/3/29 21:09
   * @version: 1.0.1
   * Modification History:
   * Date         Author          Version            Description
   * -----------------------------------------------------------
   * 2024/3/29    cuizx        v1.0.1             init
   */
  @GetMapping("/userLogin")
  @ApiOperation(value = "用户登录", notes = "用户登录")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "userName", value = "登录账号", dataTypeClass = String.class),
      @ApiImplicitParam(name = "password", value = "登录密码", dataTypeClass = String.class)
  })
  public BaseResult<Member> login(@RequestParam("userName") String userName, @RequestParam("password") String password)
  {

    Member user = memberService.getByUsernameAndPassword(userName, password);

    return BaseResult.success(ResultEnum.SUCCESS_CODE, user);
  }

  /**
   * <p>todo 获取用户信息</p>
   * @param: userId
   * @return: com.king.platform.entity.BaseResult<java.util.Map>
   * @author: cuizx
   * @date: 2024/3/29 21:48
   * @version: 1.0.1
   * Modification History:
   * Date         Author          Version            Description
   * -----------------------------------------------------------
   * 2024/3/29    cuizx        v1.0.1             init
   */
  @GetMapping("/userInfo")
  @ApiOperation(value = "查询用户信息", notes = "查询用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "userId", value = "用户ID", dataTypeClass = String.class)
  })
  public BaseResult<Map> getUserInfo(int userId)
  {
    return BaseResult.success(ResultEnum.SUCCESS_CODE, memberService.getUserInfo(userId));
  }

}
